package com.sunwoda.controller;

import com.sunwoda.entity.User;
import com.sunwoda.service.UserService;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * (User)表控制层
 *
 * @author makejava
 * @since 2021-09-04 15:26:52
 */
@Controller
@RequestMapping("user")
public class UserController {
    /**
     * 服务对象
     */

    @Resource
    private UserService userService;

    /**
     * 通过主键查询单条数据
     *
     * @param id 主键
     * @return 单条数据
     */
    @GetMapping("selectOne")
    public String selectOne(Integer id) {
        System.out.println(this.userService.queryById(id).toString());
        return "success";
    }

    /**
    * @Description: 登录
    * @Param:
    * @return:
    * @Author: SGR
    * @Date: 2021-09-09
    */
    @GetMapping("/login")
    public String login(@RequestParam(value = "name") String name,@RequestParam(value = "password") String password){
        User user = new User();
        user.setName(name);
        user.setPassword(password);
        boolean login = this.userService.login(user);
        if (login){
            return "success";
        }else {
            return "error";
        }
    }

    /**
    * @Description: 登录2
    * @Param:
    * @return:
    * @Author: SGR
    * @Date: 2021-09-09
    */
    @PostMapping("/login2")
    public String login2(@RequestBody User user){
        boolean login  = this.userService.login(user);
        if (login){
            return "success";
        }else {
            return "error";
        }
    }


}
